package com.mikey.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.mikey.common.ApiResult;
import com.mikey.common.PageResult;
import com.mikey.pojo.TbBrand;
import com.mikey.service.BrandService;
import org.apache.ibatis.annotations.Param;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @author :Mikey
 * @description :
 * @create :2022-06-28 10:54:00
 */
@RestController
@RequestMapping("/brand")
public class BrandController {
    @Reference
    BrandService brandService;

    @RequestMapping("/findAll")
    public ApiResult findAll() {
        return ApiResult.success(true, "success", brandService.findAll());
    }

    @RequestMapping("/findOne")
    public ApiResult findOne(Long id) {
        return ApiResult.success(true, "success", brandService.findOne(id));
    }

    @RequestMapping("/deleteBrand")
    public ApiResult deleteBrand(Long ids[]) {
        if (brandService.deleteByIds(ids) > 0) {
            return ApiResult.success(true, "success",null);
        }
        return  ApiResult.success(false,"error",null);
    }

    @RequestMapping("/updateBrand")
    public ApiResult updateBrand(@RequestBody TbBrand brand) {
        if (brandService.updateBrand(brand) > 0) {
            return ApiResult.success(true, "success", null);
        }
        return  ApiResult.success(false,"error",null);
    }

    @RequestMapping("/addBrand")
    public ApiResult addBrand(@RequestBody TbBrand brand) {
        if (brandService.addBrand(brand) > 0) {
            return ApiResult.success(true, "success", null);
        }
        return  ApiResult.success(false,"error",null);
    }
    @RequestMapping("/findPage")
    public ApiResult findPage(int page,int rows) {
        return ApiResult.success(true,"success",brandService.findPage(page, rows));
    }
    @RequestMapping("/search")
    public ApiResult findByKwd(@RequestBody TbBrand tbBrand,int page,int rows) {
        PageResult pageResult = brandService.findByKwd(tbBrand, page, rows);
        return new ApiResult(true,"success",pageResult);
    }
    @RequestMapping("/selectOptionList")
    public  List<Map> selectOptionList(){
        return  brandService.selectOptionList();
    }
}
